package pers.aidenj.ostrich.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import pers.aidenj.ostrich.common.VerificationCode;
import pers.aidenj.ostrich.service.LoginService;

@Controller
public class LoginContorller {

	@Resource
	LoginService loginService;
	
	/**
	 * 前台用户登陆
	 * 
	 * @author AidenJ
	 * @date 2017年4月7日 16:05:46
	 * @param account
	 * @param password
	 * @param verifyCode
	 * @return
	 */
	@RequestMapping(value="user_login", method=RequestMethod.POST, produces="application/json" )
	@ResponseBody
	public JSONObject userLogin(String account, String password, String verifyCode){
		return loginService.userLogin(account,password,verifyCode);
	}
	
	/**
	 * 后台用户登陆
	 * 
	 * @author AidenJ
	 * @date 2017年4月7日 16:05:46
	 * @param account 账号
	 * @param password 密码
	 * @param verifyCode 验证码
	 * @param uuid 请求的标识
	 * @return
	 */
	@RequestMapping(value="admin_login", method=RequestMethod.POST, produces="application/json" )
	@ResponseBody
	public JSONObject adminLogin(HttpSession httpSession, String account, String password, String verifyCode, String uuid, Model model){
		return loginService.adminLogin(httpSession,account,password,verifyCode,uuid,model);
	}
	/**
	 * 验证码
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="getVerificationCode", method=RequestMethod.GET)
	public void getVerificationCode(HttpServletRequest request,HttpServletResponse response){
		VerificationCode.getRandImg(request, response);
	}
	
}
